import pandas as pd
import numpy as np
import os
#from WindPy import w
#w.start()

data=pd.read_excel('综合信息查询_组合证券_312_20200219.xls')
position=list(data['持仓'])
stocks=list(data['证券代码'])
names=list(data['证券名称'])
mv=list(data['市值'])
price=list(data['最新价'])
codeList=[]
mycodes=set([])
for i in range(len(stocks)):
    if np.isnan(stocks[i]):
        continue
        
    code=int(stocks[i])
    pos=position[i]
    #pos=np.floor(pos/190)*100
    codeStr=str(code).rjust(6,'0')
    if ((codeStr<'009999')|((codeStr>='300000') & (codeStr<='309999'))):
        codeStr+='.SZ'
    elif ((codeStr>='600000') & (codeStr<='609999')):
        codeStr+='.SH'
    else:
        continue
    codeList.append({'code':codeStr,'hold':pos,'name':names[i],'marketValue':mv[i],'price':price[i]})
myStocks=pd.DataFrame(codeList)

myCodeName=myStocks[['code','hold','name','price']]

df=pd.DataFrame(myStocks.groupby(['code'])['hold'].sum())
df['preClose']=myStocks.groupby(['code'])['price'].mean()
df['marketValue']=myStocks.groupby(['code'])['marketValue'].sum()

filename='312.h5'
with pd.HDFStore(filename,'a',complib='blosc:zstd',append=False,complevel=9) as store:
    store.append('data',df,append=False,format="table",data_columns=df.columns)







